<?php

namespace App\Http\Controllers;

use App\Models\AppRelease;
use App\Services\Uri;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;

class AppController extends Controller
{

    /**
     * @api {GET} /api/appazv/v 自动更新
     * @apiGroup APP
     * @apiDescription 获取最新的安卓APK安装包信息
     * @apiUse PublicCommonBlock
     * @apiSuccessExample {json} 成功相应示例
     * {"code":200,"msg":"success","data":{"add_time":"2021-04-28 15:01:14","force":1,"version_name":"1.0.1","path":"http://tikball.test/uploads/tikball_v1.0.1.apk","version_code":101,"desclist":["\u4fee\u590d\u5df2\u77e5BUG"]}}
     */
    public function getRelease(Request $request) : Response
    {
        /* @var AppRelease $model */
        $model = AppRelease::query()->where(['state'=>1])->orderByDesc('id')->first();

        $data = [
            'add_time' => $model->created_at,
            'force' => $model->force_update,
            'version_name' => $model->version_name,
            'path' => Uri::createAppUrl($model->path),
            'version_code' => $model->version_code,
            'desclist' => array_values($model->getDescriptionList())
        ];
        return $this->success($data);
    }

}
